// pages/exhibition/sessions/sessions.js
Page({
  data: {
    sessionList: [
      {
        id: 1,
        title: '生命教育主题展',
        date: '2025.08.20',
        time: '09:00-11:00',
        location: '生命教育展馆A厅',
        totalSeats: 50,
        remainingSeats: 15,
        status: 'available',
        description: '通过多媒体展示和互动体验，深入了解生命的意义和价值。'
      },
      {
        id: 2,
        title: '捐献者故事分享会',
        date: '2025.08.22',
        time: '14:00-16:00',
        location: '生命教育展馆B厅',
        totalSeats: 30,
        remainingSeats: 0,
        status: 'full',
        description: '邀请捐献者家属分享感人故事，传递生命教育理念。'
      },
      {
        id: 3,
        title: '医学知识科普展',
        date: '2025.08.25',
        time: '10:00-12:00',
        location: '生命教育展馆C厅',
        totalSeats: 40,
        remainingSeats: 25,
        status: 'available',
        description: '普及医学知识，了解人体器官捐献的重要性。'
      },
      {
        id: 4,
        title: '生命意义探讨会',
        date: '2025.08.28',
        time: '15:00-17:00',
        location: '生命教育展馆D厅',
        totalSeats: 35,
        remainingSeats: 20,
        status: 'available',
        description: '与专家学者一起探讨生命的意义和价值。'
      },
      {
        id: 5,
        title: '捐献流程介绍',
        date: '2025.08.30',
        time: '13:00-15:00',
        location: '生命教育展馆E厅',
        totalSeats: 45,
        remainingSeats: 30,
        status: 'available',
        description: '详细介绍遗体捐献的流程和注意事项。'
      }
    ]
  },

  onLoad(options) {
    console.log('场次列表页面加载');
    this.loadSessions();
  },

  // 加载场次数据
  loadSessions() {
    // 这里可以从服务器获取场次数据
    console.log('加载场次数据');
  },

  // 查看场次详情
  viewSessionDetail(e) {
    const id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: `/pages/exhibition/session-detail/session-detail?id=${id}`
    });
  },

  // 预约场次
  makeReservation(e) {
    const id = e.currentTarget.dataset.id;
    const session = this.data.sessionList.find(item => item.id == id);
    
    if (!session) {
      wx.showToast({
        title: '场次信息不存在',
        icon: 'none'
      });
      return;
    }

    if (session.status !== 'available') {
      wx.showToast({
        title: '该场次已满员',
        icon: 'none'
      });
      return;
    }

    // 跳转到预约页面
    wx.navigateTo({
      url: `/pages/exhibition/reservation/reservation?sessionId=${id}`
    });
  },

  // 下拉刷新
  onPullDownRefresh() {
    this.loadSessions();
    setTimeout(() => {
      wx.stopPullDownRefresh();
    }, 1000);
  }
});
